package com.wobangkj.common.repository;

import com.wobangkj.common.model.crud.Collect;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface CollectRepository extends JpaRepository<Collect, Long> {
    @Query(nativeQuery = true, value="select * from  collect  where collector_id=:collector_id and collect_text_id=:collect_text_id and collect_class=:collect_class  ")
    List<Collect> findById(String collector_id, String collect_text_id, String collect_class);

    @Query(nativeQuery = true, value="update share set share_collect_num=share_collect_num+1 where id=:id  ")
    @Modifying
    public void updateShareNumById(Long id);

    @Query(nativeQuery = true, value="update job set job_collect_num=job_collect_num+1 where id=:id  ")
    @Modifying
    public void updateJobNumById(Long id);

    @Query(nativeQuery = true, value="update share set share_collect_num=share_collect_num-1 where share.id in (select collect_text_id from collect WHERE collect.id = :id) ")
    @Modifying
    public void deleteShareNumById(Long id);

    @Query(nativeQuery = true, value="update job set job_collect_num=job_collect_num-1 where job.id in (select collect_text_id from collect WHERE collect.id = :id)  ")
    @Modifying
    public void deleteJobNumById(Long id);

    @Query(nativeQuery = true, value="select id from  collect  where collector_id=:collector_id and collect_text_id=:collect_text_id and collect_class=:collect_class ")
    public Long findCollect(String collector_id, String collect_text_id, String collect_class);
}
